package com.yulebaby.callsenter.task;

import com.yulebaby.callsenter.bean.CustomerBean;
import com.yulebaby.callsenter.bean.multiplebean.MultipleCustomerBean;
import com.yulebaby.callsenter.utils.DateUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.ListIterator;

/**
 * Author: Zhangbo
 * Time: 2016/12/2
 */
public class CustomerDataConformTask {
    /**
     * 根据下次跟踪时间进行转换
     *
     * @param list
     */
    public static List<MultipleCustomerBean> doReturnVisitDataConform(List<CustomerBean> list) {
        ArrayList<MultipleCustomerBean> newList = new ArrayList<>();
        ArrayList<String> timeList = new ArrayList<>();
        for (CustomerBean customerBean : list) {
            String nextVisitTime = DateUtil.formatDateTime(customerBean.getVisit_date());
            if (!timeList.contains(nextVisitTime)) {
                timeList.add(nextVisitTime);
                newList.add(new MultipleCustomerBean(MultipleCustomerBean.TIME, nextVisitTime));
            }
            newList.add(new MultipleCustomerBean(MultipleCustomerBean.CUSTOMERITEM, customerBean));
        }
        return newList;
    }

    /**
     * 根据分配时间进行转换
     *
     * @param list
     */
    public static List<MultipleCustomerBean> doCustomerDataConform(List<CustomerBean> list) {
        ArrayList<MultipleCustomerBean> newList = new ArrayList<>();
        ArrayList<String> timeList = new ArrayList<>();
        ListIterator<CustomerBean> listIterator = list.listIterator();
        while (listIterator.hasNext()){
            CustomerBean customerBean = listIterator.next();
            String allocTime = DateUtil.formatDateTime(customerBean.getAlloc_time());
            if (!timeList.contains(allocTime)) {
                timeList.add(allocTime);
                newList.add(new MultipleCustomerBean(MultipleCustomerBean.TIME, allocTime));
            }
            newList.add(new MultipleCustomerBean(MultipleCustomerBean.CUSTOMERITEM, customerBean));
        }

        return newList;
    }

    public static List<MultipleCustomerBean> doCustomerDataConformAndSequence(List<CustomerBean> list) {
        Collections.sort(list, new Comparator<CustomerBean>() {
            @Override
            public int compare(CustomerBean o1, CustomerBean o2) {
                int i = o2.getAlloc_time().compareTo(o1.getAlloc_time());
                if (i == 0) {
                    return o2.getStage().compareTo(o1.getStage());
                }
                return i;
            }
        });
        return doCustomerDataConform(list);
    }

    /**
     * 根据投公海的时间进行转换
     *
     * @param list
     */
    public static List<MultipleCustomerBean> doGoSeaDataConform(List<CustomerBean> list) {
        ArrayList<MultipleCustomerBean> newList = new ArrayList<>();
        ArrayList<String> timeList = new ArrayList<>();
        for (CustomerBean customerBean : list) {
            String dayNumber = String.valueOf(customerBean.getDay_number());
            if (!timeList.contains(dayNumber)) {
                timeList.add(dayNumber);
                newList.add(new MultipleCustomerBean(MultipleCustomerBean.TIME, dayNumber));
            }
            newList.add(new MultipleCustomerBean(MultipleCustomerBean.CUSTOMERITEM, customerBean));
        }
        return newList;
    }
}
